// helpers.cpp
#include "helpers.h"
#include "goboard.h"

bool is_point_an_eye(const Board& board, const Point& point, Player color) {
    if (board.get(point) != Player::Black && board.get(point) != Player::White) {
        // Empty point, continue
    } else {
        return false;
    }

    // Check all neighbors
    for (const auto& neighbor : point.neighbors()) {
        if (board.is_on_grid(neighbor)) {
            Player neighbor_color = board.get(neighbor);
            if (neighbor_color != color) {
                return false;
            }
        }
    }

    // Check corners
    int friendly_corners = 0;
    int off_board_corners = 0;
    std::vector<Point> corners = {
        Point(point.row - 1, point.col - 1),
        Point(point.row - 1, point.col + 1),
        Point(point.row + 1, point.col - 1),
        Point(point.row + 1, point.col + 1)
    };

    for (const auto& corner : corners) {
        if (board.is_on_grid(corner)) {
            Player corner_color = board.get(corner);
            if (corner_color == color) {
                friendly_corners++;
            }
        } else {
            off_board_corners++;
        }
    }

    if (off_board_corners > 0) {
        return (off_board_corners + friendly_corners) == 4;
    }

    return friendly_corners >= 3;
}
